**************************************************************************************************************
**PROJECT: HOUSEHOLD APPLIANCE REPLACEMENT SUBSIDIES**********************************************************
**************************************************************************************************************
clear all



use "Full Subsidy Data.dta", clear

*******************************************************************************************************************
*************************************MINIMAL DATA CLEAN************************************************************
*******************************************************************************************************************
drop if id==""

replace price=. if price<0 	& price!=.
replace price=. if price==0 & price!=.

replace price_eur=. if price_eur<0 	& price_eur!=.
replace price_eur=. if price_eur==0 & price_eur!=.

replace units=. if units<0 	& units!=.
replace units=. if units<2  & units!=.

replace annual_energy_consumption="" if annual_energy_consumption=="n.a."
replace annual_energy_consumption="" if annual_energy_consumption=="unknown"
replace annual_energy_consumption="" if annual_energy_consumption=="0"
replace annual_energy_consumption="" if annual_energy_consumption=="1"
replace annual_energy_consumption="" if annual_energy_consumption=="2"
replace annual_energy_consumption="" if annual_energy_consumption=="8500"
replace annual_energy_consumption="" if annual_energy_consumption=="9999"
destring annual_energy_consumption, replace

*******************************************************************************************************************
*************************************SUMMARY STATISTICS FULL DATA**************************************************
*******************************************************************************************************************

sum units
replace price_eur=price if country=="Germany"
replace price_eur=price if country=="Austria"

sum price_eur
sum annual_energy_consumption

by id country, sort: egen 	firstyear	=min(year)
by id country, sort: egen 	firstdate	=min(date)
by id country, sort: gen 	mage		=date-firstdate+1
gen mage2=mage*mage

sum mage

by id country, sort: gen n=_n
replace n=0 if n>1
by id, sort: egen sumn=sum(n)

sum sumn

tab country
tab category

*******************************************************************************************************************
*************************************SUMMARY STATISTICS BY PRODUCT CATEGORY****************************************
*******************************************************************************************************************

sum units 							if (category=="refrigerator"|category=="freezer")
sum price_eur 						if (category=="refrigerator"|category=="freezer")
sum annual_energy_consumption		if (category=="refrigerator"|category=="freezer")


sum units 							if (category=="refrigerator"|category=="freezer") & energy_label_eu=="A+++"
sum price_eur 						if (category=="refrigerator"|category=="freezer") & energy_label_eu=="A+++"
sum annual_energy_consumption		if (category=="refrigerator"|category=="freezer") & energy_label_eu=="A+++"


sum units 							if (category=="refrigerator"|category=="freezer") & energy_label_eu=="A++"
sum price_eur 						if (category=="refrigerator"|category=="freezer") & energy_label_eu=="A++"
sum annual_energy_consumption		if (category=="refrigerator"|category=="freezer") & energy_label_eu=="A++"

sum units 							if (category=="refrigerator"|category=="freezer") & energy_label_eu=="A+"
sum price_eur 						if (category=="refrigerator"|category=="freezer") & energy_label_eu=="A+"
sum annual_energy_consumption		if (category=="refrigerator"|category=="freezer") & energy_label_eu=="A+"

sum units 							if (category=="refrigerator"|category=="freezer") & energy_label_eu!="A+" & energy_label_eu!="A++" &energy_label_eu!="A+++"
sum price_eur 						if (category=="refrigerator"|category=="freezer") & energy_label_eu!="A+" & energy_label_eu!="A++" &energy_label_eu!="A+++"
sum annual_energy_consumption		if (category=="refrigerator"|category=="freezer") & energy_label_eu!="A+" & energy_label_eu!="A++" &energy_label_eu!="A+++"


sum units 							if (category=="washing machine")
sum price_eur 						if (category=="washing machine")
sum annual_energy_consumption		if (category=="washing machine")


sum units 							if (category=="washing machine") & energy_label_eu=="A+++"
sum price_eur 						if (category=="washing machine")  & energy_label_eu=="A+++"
sum annual_energy_consumption		if (category=="washing machine")  & energy_label_eu=="A+++"


sum units 							if (category=="washing machine") & energy_label_eu=="A++"
sum price_eur 						if (category=="washing machine") & energy_label_eu=="A++"
sum annual_energy_consumption		if (category=="washing machine") & energy_label_eu=="A++"

sum units 							if (category=="washing machine") & energy_label_eu=="A+"
sum price_eur 						if (category=="washing machine") & energy_label_eu=="A+"
sum annual_energy_consumption		if (category=="washing machine") & energy_label_eu=="A+"

sum units 							if (category=="washing machine") & energy_label_eu!="A+" & energy_label_eu!="A++" &energy_label_eu!="A+++"
sum price_eur 						if (category=="washing machine") & energy_label_eu!="A+" & energy_label_eu!="A++" &energy_label_eu!="A+++"
sum annual_energy_consumption		if (category=="washing machine") & energy_label_eu!="A+" & energy_label_eu!="A++" &energy_label_eu!="A+++"



 *********************************************
 ***** DROP MODELS SOLD IN ONLY ONE COUNTRY***
 *********************************************

tab sumn 
drop if sumn==1


 ************************************************************************
 ***** DROP MODELS SOLD IN ONLY ONE COUNTRY WITHIN A PRODUCT-DATE CELL***
 ************************************************************************

by id country date, sort: gen j=_n
replace j=0 if j>1
by id date, sort: egen sumj=sum(j)

tab sumj 

drop if sumj==1

 
*******************************************************************************************************************
*************************************SUMMARY STATISTICS ESTIMATION SAMPLE******************************************
*******************************************************************************************************************

sum units
sum price_eur
sum mage
sum annual_energy_consumption
sum sumn

tab country
tab category


